package advanced.sorm.utils;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * 封装了反射常用的工具类
 */
public class ReflectUtils {
    public static Object invokeGet(String fieldName, Object o) {
        try {
            Class<?> clz = o.getClass();
            Method method = clz.getMethod(("get" + STringUtils.firstChar2Upper(fieldName)), null);
            Object prikeyInvoke = method.invoke(o, null);//获取到主键的值
            return method.invoke(o, null);
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
        return null;
    }
}
